[分享][Hexo][Hexo其它設定]

hexo內 設置 RSS, Sitemap, Disqus

設置 RSS

  1. 安裝RSS插件,到blog目錄下,輸入
    blog/
    1
    npm install hexo-generator-feed
  2. 到blog目錄下找到_config.yml,在# Plugins部分加上
    blog/_config.yml
    1
    2
    plugins:
    - hexo-generator-feed
  3. 到下方,# RSS hexo-generator-feed部分改成
    blog/_config.yml
    1
    2
    3
    4
    5
    # RSS hexo-generator-feed
    feed:
    type: atom
    path: atom.xml
    limit: 20
  4. 到theme資料夾,你的主題底下找_config.yml檔案,到裡面rss的地方,改成
    blog/theme/themename/_config.yml
    1
    rss: /atom.xml
  5. 輸入hexo generate 讓RSS產生出來,會產生在public資料夾裡面

設置 Sitemap

  1. 安裝Sitemap插件,到blog目錄下,輸入
    blog/
    1
    npm install hexo-generator-sitemap
  2. 到blog目錄下找到_config.yml,在# Plugins部分加上
    blog/_config.yml
    1
    2
    plugins:
    - hexo-generator-sitemap
  3. 輸入hexo generate 讓RSS產生出來,會產生在blog/public資料夾裡面

Sitemap是為了讓搜尋引擎可以搜到你的blog,最好自己向Google或是百度加入blog的sitemap.xml

sitemap.xml裡面不可以有”&”號(因為年少的錯誤,常常在文章主旨放入”&”,導致sitemap.xml會無法parse,把&全部修掉後才正常能正常運作)

設置 Disqus

Disqus是一套整合性留言管理系統
因為Hexo只是靜態頁面,沒有資料庫在背後支持留言系統,只好靠第三方的留言管理系統

  1. Disqus官網註冊帳號
  2. 到blog目錄下找到_config.yml,在# Disqus的部分加上自己的shortname
    blog/_config.yml
    1
    2
    # Disqus
    disqus_shortname: blake31113
  3. themes/themename/layout/_partial修改comment.ejs
    blog/themes/themename/layout/_partial/comment.ejs
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    <% if (page.comments){ %>
    <section id="comment">
    <h1 class="title"><%= __('comment') %></h1>
    <% if (theme.comment_provider == "facebook") {
    if (theme.facebook) { %>
    <%- partial('_partial/facebook_comment', {fbConfig: theme.facebook}) %>
    <% } %>
    <% } else if(config.disqus_shortname) { %>
    <div id="disqus_thread">
    <noscript>Please enable JavaScript to view the <a href="//disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
    </div>
    <% } %>
    </section>
    <% } %>

使用git上傳發生錯誤:「warning: LF will be replaced by CRLF」

因為 Windows 環境下,換行會變成 CRLF , Linux 和現在的 Mac OS 換行則是 LF
雖然不會影響執行結果,不過如果覺得礙眼
可以到blog/.deply/.git(可能為隱藏),找cofig檔,在[core]裡面加入autocrlf = false,如下

blog/.deply/.git/cofig
1
2
3
4
5
6
7
8
9
[core]
repositoryformatversion = 0
filemode = false
bare = false
logallrefupdates = true
symlinks = false
ignorecase = true
hideDotFiles = dotGitOnly
autocrlf = false

就會自己忽略CRLF